﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using FubiManger.Controls;
using System.Data;

namespace FubiManger.UI
{
    partial class GoodsForm : Smobiler.Core.Controls.MobileForm
    {
        /// <summary>
        /// 商品管理
        /// </summary>
        public GoodsForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 商品集合
        /// </summary>
        List<ms_goods> gdlist = new List<ms_goods>();
        private string status = "1";
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }

        private void GoodsForm_Load(object sender, EventArgs e)
        {
            gdlist = goodsDal.Querybymerchantid(merchantid, status);
            Getgood();
        }
        /// <summary>
        /// 加载数据
        /// </summary>
        private void Getgood()
        {
            //if (pangoods.Controls.Count > 0)
            //    pangoods.Controls.Clear();
            //pangoods.Height = gdlist.Count * 106;
            lvgoods.Rows.Clear();
            DataTable table = new DataTable();
            table.Columns.Add("goodname");
            table.Columns.Add("status");
            table.Columns.Add("markprice");
            table.Columns.Add("price");
            table.Columns.Add("classname");
            table.Columns.Add("goodid");
            table.Columns.Add("classify_id");
            table.Columns.Add("cover");
            table.Columns.Add("merchantid");
            for (int i = 0; i < gdlist.Count; i++)
            {
                //goodscontrol con = new goodscontrol();
                //con.cover = gdlist[i].cover;
                //con.goodname = gdlist[i].goods_name;//商品名称
                //con.price = gdlist[i].price;//价格
                //con.market_price = gdlist[i].market_price;//市场价
                //con.classify_id = gdlist[i].classify_id;//分类ID
                //con.status = gdlist[i].status;//1上架2下架
                //con.goodid = gdlist[i].id;//商品ID
                //con.merchantid = merchantid;//商家ID
                //pangoods.Controls.Add(con);
                table.Rows.Add(gdlist[i].goods_name, gdlist[i].status,"原价："+ gdlist[i].market_price, "￥"+gdlist[i].price, gdlist[i].classify_name, gdlist[i].id, gdlist[i].classify_id, @"C:\fbimage\"+gdlist[i].cover, gdlist[i].merchant_id);
            }
            lvgoods.DataSource = table;
            lvgoods.DataBind();
        }

        /// <summary>
        /// 已上架
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btny_Press(object sender, EventArgs e)
        {
            btny.ForeColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btny.BorderColor= System.Drawing.Color.FromArgb(207, 29, 32);
            btnn.ForeColor = System.Drawing.Color.DimGray;
            btnn.BorderColor= System.Drawing.Color.Transparent;
            status = "1";
            gdlist = goodsDal.Querybymerchantid(merchantid, status);
            Getgood();
        }
        /// <summary>
        /// 已下架
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnn_Press(object sender, EventArgs e)
        {
            btnn.ForeColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btnn.BorderColor = System.Drawing.Color.FromArgb(207, 29, 32);
            btny.ForeColor = System.Drawing.Color.DimGray;
            btny.BorderColor = System.Drawing.Color.Transparent;
            status = "2";
            gdlist = goodsDal.Querybymerchantid(merchantid, status);
            Getgood();
        }
        /// <summary>
        /// 刷新
        /// </summary>
        public void Resfh()
        {
            gdlist = goodsDal.Querybymerchantid(merchantid, status);
            Getgood();
        }

        private void txtgoodname_TextChanged(object sender, EventArgs e)
        {
            gdlist = goodsDal.Querybygoodname(merchantid, status,txtgoodname.Text);
            Getgood();
        }
    }
}